using System;
using System.Collections.Generic;
using System.Text;

namespace Adge.Common
{
    public class SingletonProvider<T> where T : new()
    {
        SingletonProvider() { }

        public static T Instance
        {
            get { return SingletonCreator.instance; }
        }

        class SingletonCreator
        {
            static SingletonCreator() { }

            internal static readonly T instance = new T();
        }
    }

    public sealed class Singleton
    {
        private Singleton()
        {
        }

        public static Singleton Instance
        {
            get
            {
                return SingletonCreator.instance;
            }
        }

        internal class SingletonCreator
        {
            // Explicit static constructor to tell C# compiler
            // not to mark type as beforefieldinit
            static void Nested()
            {
            }

            internal static readonly Singleton instance = new Singleton();
        }
    }
}
